package com.moon.mybatisplus.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.moon.mybatisplus.entity.Dog;
import com.moon.mybatisplus.service.DogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：xxx
 * @description：TODO
 * @date ：2023/12/14 15:41
 */
@RestController
@Slf4j
@RequestMapping("dog")
public class DogController {
    @Autowired
    private DogService dogService;

    @PostMapping("add")
    public String add(@RequestBody Dog dog) {
        dogService.save(dog);
        return "SUCCESS";
    }

    @PostMapping("pageAll")
    public PageInfo<Dog> pageAll(Integer currentPage,Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        Page<Dog> page = dogService.page(new Page<>());
        return new PageInfo(page.getRecords());
//        page.setTotal(dogService.count());
//        return page;
    }

    @GetMapping("getAll")
    public PageInfo<Dog> getAll() {
        Page<Dog> page = dogService.page(new Page<>());
        return new PageInfo(page.getRecords());
    }
}
